/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.hk.sys.web.user;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.hk.sys.entity.user.HkAdvReport;
import com.thinkgem.jeesite.modules.hk.sys.service.user.HkAdvReportService;

/**
 * 用户举报Controller
 * @author 罗天文
 * @version 2018-03-19
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/user/hkAdvReport")
public class HkAdvReportController extends BaseController {

	@Autowired
	private HkAdvReportService hkAdvReportService;
	
	@ModelAttribute
	public HkAdvReport get(@RequestParam(required=false) String id) {
		HkAdvReport entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = hkAdvReportService.get(id);
		}
		if (entity == null){
			entity = new HkAdvReport();
		}
		return entity;
	}
	
	@RequiresPermissions("sys:user:hkAdvReport:view")
	@RequestMapping(value = {"list", ""})
	public String list(HkAdvReport hkAdvReport, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<HkAdvReport> page = hkAdvReportService.findPage(new Page<HkAdvReport>(request, response), hkAdvReport); 
		model.addAttribute("page", page);
		return "hk/sys/user/hkAdvReportList";
	}

	@RequiresPermissions("sys:user:hkAdvReport:view")
	@RequestMapping(value = "form")
	public String form(HkAdvReport hkAdvReport, Model model) {
		model.addAttribute("hkAdvReport", hkAdvReport);
		return "hk/sys/user/hkAdvReportForm";
	}

	@RequiresPermissions("sys:user:hkAdvReport:edit")
	@RequestMapping(value = "save")
	public String save(HkAdvReport hkAdvReport, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, hkAdvReport)){
			return form(hkAdvReport, model);
		}
		hkAdvReportService.save(hkAdvReport);
		addMessage(redirectAttributes, "保存用户举报成功");
		return "redirect:"+Global.getAdminPath()+"/sys/user/hkAdvReport/?repage";
	}
	
	@RequiresPermissions("sys:user:hkAdvReport:edit")
	@RequestMapping(value = "delete")
	public String delete(HkAdvReport hkAdvReport, RedirectAttributes redirectAttributes) {
		hkAdvReportService.delete(hkAdvReport);
		addMessage(redirectAttributes, "删除用户举报成功");
		return "redirect:"+Global.getAdminPath()+"/sys/user/hkAdvReport/?repage";
	}

}